//
// Created by xili on 2024/8/21 17:41.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    vector<int> rearrangeArray(vector<int> &nums) {
        vector<int> ans;
        int n = nums.size();
        int pos = 0, neg = 0;
        for (int i = 0; i < n / 2; i++) {
            while (nums[pos] < 0) {
                pos++;
            }
            ans.push_back(nums[pos++]);
            while (nums[neg] > 0) {
                neg++;
            }
            ans.push_back(nums[neg++]);
        }
        return ans;
    }
};